import { Component, OnInit, AfterViewInit, AfterViewChecked, AfterContentChecked, OnChanges } from '@angular/core';
import { Route, Router } from '../../../../node_modules/@angular/router';
import { MainService } from '../../service/main.service';
import * as $ from 'jquery'


@Component({
  selector: 'app-same-temps',
  templateUrl: './same-temps.component.html',
  styleUrls: ['./same-temps.component.css']
})
export class SameTempsComponent implements OnInit,AfterViewInit,AfterViewChecked {
  swiper:Swiper
  page:string = this.router.url.split('/',2)[1]
  article:string = this.router.url.split('/',3)[2]
  firstLink
  webName
  navLists
  lists
  contList
  mark
  mainUrl
  selected=''
  listSelected



  constructor(private router:Router,private service:MainService) { 
    this.mainUrl=this.service.mainUrl
    switch(this.page){
      case 'jituangaikuang':
      // console.log('niubi');
      
      this.firstLink='jituangaikuang'
      this.webName = '集团概况'
      this.service.getFirstFLList('1',res=>{
        console.log(res);
        this.navLists=res.list 
        if(this.article){
          this.service.getFromServ('/api/index/get_art'+'?id='+this.article,{},res=>{
            console.log(res);
            $('#artContent').html(res.article.content)
          },err=>{})
         }else{
          this.changeList({'id':res.list[0].id})
        }
      })
      break;
    case 'xinwenzhongxin':
    this.firstLink='xinwenzhongxin';
      this.webName = '新闻中心';
      console.log(this.article);
      
      this.service.getFirstFLList('3',res=>{
       // console.log(res);
       this.navLists=res.list 
       if(this.article){
         this.service.getFromServ('/api/index/get_art'+'?id='+this.article,{},res=>{
           console.log(res);
           $('#artContent').html(res.article.content)
          //  $('.RAContent').html(res.article.content)
          //  this.articleTitle=res.article.title
          //  this.RLName=res.nav.s_title;
          //  this.firstTitle=res.nav.f_title;
          //  this.publishDate=res.article.publish_time
         },err=>{})
        }else{
          this.changeList({'id':res.list[0].id})
       }
      })
      break;
    case 'gongsiyeji':
    this.firstLink='gongsiyeji'
      this.webName = '公司业绩'
      this.service.getFirstFLList('4',res=>{
        console.log(res);
        this.navLists=res.list 
        if(this.article){
          this.service.getFromServ('/api/index/get_art'+'?id='+this.article,{},res=>{
            console.log(res);
             $('#artContent').html(res.article.content)
            // $('.RAContent').html(res.article.content)
            // this.articleTitle=res.article.title
            // this.RLName=res.nav.s_title;
            // this.firstTitle=res.nav.f_title;
            // this.publishDate=res.article.publish_time
          },err=>{})
         }else{
          this.changeList({'id':res.list[0].id})
        }
      })
      break;
    case 'kejichuangxin':
    this.firstLink='kejichuangxin'
      this.webName = '科技创新'
      this.service.getFirstFLList('5',res=>{
        console.log(res);
        // var _that=this
        this.navLists=res.list 
        if(this.article){
          this.service.getFromServ('/api/index/get_art'+'?id='+this.article,{},res=>{
            console.log(res);
             $('#artContent').html(res.article.content)

            // $('.RAContent').html(res.article.content)
            // this.articleTitle=res.article[0].title
            // this.RLName=res.nav.s_title;
            // this.firstTitle=res.nav.f_title;
            // this.publishDate=res.article.publish_time
          },err=>{})
         }else{
          this.changeList({'id':res.list[0].id})
        }
      })
      break;
    case 'qiyewenhua':
    this.firstLink='qiyewenhua'
      this.webName = '企业文化'
      this.service.getFirstFLList('6',res=>{
        // console.log(res);
        this.navLists=res.list 
        if(this.article){
          this.service.getFromServ('/api/index/get_art'+'?id='+this.article,{},res=>{
            console.log(res);
             $('#artContent').html(res.article.content)
            // $('.RAContent').html(res.article.content)
            // this.articleTitle=res.article.title
            // this.RLName=res.nav.s_title;this.firstTitle=res.nav.f_title;
            // this.publishDate=res.article.publish_time
          },err=>{})
         }else{
          this.changeList({'id':res.list[0].id})
        }
      })
      break;
    case 'zhaocaigonggao':
    this.firstLink='zhaocaigonggao'
      this.webName = '招采公告'
      this.service.getFirstFLList('7',res=>{
        // console.log(res);
        this.navLists=res.list 
        if(this.article){
          this.service.getFromServ('/api/index/get_art'+'?id='+this.article,{},res=>{
            console.log(res);
             $('#artContent').html(res.article.content)
            // $('.RAContent').html(res.article.content)
            // this.articleTitle=res.article.title
            // this.RLName=res.nav.s_title;this.firstTitle=res.nav.f_title;
            // this.publishDate=res.article.publish_time
          },err=>{})
         }else{
           if(this.mark){

           }
          this.changeList({'id':res.list[0].id})
          
        }
      })
      break;
    case 'renliziyuan':
    this.firstLink='renliziyuan'
      this.webName = '人力资源'
      this.service.getFirstFLList('72',res=>{
        // console.log(res);
        this.navLists=res.list 
        if(this.article){
          this.service.getFromServ('/api/index/get_art'+'?id='+this.article,{},res=>{
            console.log(res);
             $('#artContent').html(res.article.content)
            // $('.RAContent').html(res.article.content)
            // this.articleTitle=res.article.title
            // this.RLName=res.nav.s_title;this.firstTitle=res.nav.f_title;
            // this.publishDate=res.article.publish_time
          },err=>{})
         }else{
         
          this.changeList({'id':res.list[0].id})
          
        }
      })
      break;
    case 'lianxiwomen':
    this.firstLink='lianxiwomen'
      this.webName = '联系我们'
      this.service.getFirstFLList('55',res=>{
        console.log(res);
        this.navLists=res.list 
        if(this.article){
          this.service.getFromServ('/api/index/get_art'+'?id='+this.article,{},res=>{
            console.log(res);
             $('#artContent').html(res.article.content)
            // $('.RAContent').html(res.article.content)
            // this.articleTitle=res.article.title
            // this.RLName=res.nav.s_title;this.firstTitle=res.nav.f_title;
            // this.publishDate=res.article.publish_time
          },err=>{})
         }else{
          this.changeList({'id':res.list[0].id})
        }
      })
      break;
      // 公司业绩单独跳转
      // case 'sytzGsyj':
      // this.firstLink='gongsiyeji'
      //   this.webName = '../../../assets/img/gsyj.jpg'
      //   this.service.getFirstFLList('4',res=>{
      //     // console.log(res);
      //     this.lists=res.list 
      //     // this.changeR(this.article)
          
      //   })
      //   break;
    }
   }

  ngOnInit() {
    // console.log('nmb');
    
   
    
   
  }
  ngAfterViewInit(){
    

  }
   ngAfterViewChecked(){
    let a = $('#artContent').find('img').width()
    let b = document.body.clientWidth
    if(a>b){
      $('#artContent').find('img').css({'width':'100%'})  
      $('#artContent').find('video').width('100%')
    }
  }


  goback(){
    window.history.back()
  }
  changeList($event){
    // console.log($event.id );
    this.listSelected= $event.id
    // $("li").removeClass('selected')
    // $("li[id="+$event.id+"]").addClass('selected')  
    this.contList=[]
    $('#artContent').html('')
    if(this.article){
      // this.mark='123'

        this.service.getFromServ('/api/index/get_art_list?'+'id='+$event.id,{},res=>{
        // console.log($event);
        if(res.art_list[1]){
          this.contList=res.art_list;
  
        }else{
          $('#artContent').html(res.article[0].content)
        }
        // this.router.navigateByUrl('/'+this.firstLink)
      },err=>{})
    }else{
      console.log($event);
      this.service.getFromServ('/api/index/get_art_list?'+'id='+$event.id,{},res=>{
        console.log(res);
        if(res.art_list[1]){
          this.contList=res.art_list;
  
        }else{
          $('#artContent').html(res.article[0].content)
         
          
        }
      },err=>{})
      
    }   
    }
    // 列表点击事件
    listClick($event){
      
      this.router.navigateByUrl(this.firstLink+'/'+$event.id)
      window.history.go()
      
    }
   
}
